<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}

else
    
    include 'lighting.html';
                
    //Manual SQL Connection
    $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
    mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());
    
    switch($_GET['action']) {
        case 'edit':
    
            switch ($_GET['type']) {
            //update bulbs
            case 'bulbs':                            

            //Date variables
            $day = $_POST['day'];
            $month = $_POST['month'];
            $year = $_POST['year'];
            
            $day2 = $_POST['day2'];
            $month2 = $_POST['month2'];
            $year2 = $_POST['year2'];

            //Function to make a valid date input
            $date = $year."-".$month."-".$day;

            //Function to make a valid date input
            $datechange = $year2."-".$month2."-".$day2;

            //SQL Query to update
            $qry = "update l_bulbs set bulb_type='".$_POST['bulb']."', watt='".$_POST['wattage']."',k_rating='".$_POST['kelvin']."', manufacturer='".$_POST['manufacturer']."',cost='".$_POST['cost']."',replacementdate='$datechange',dateinstalled='$date' where user_id='". $_SESSION['uid'] ."' and id='".$_GET['id']."'";

            break;
           
            //update hardware
            case 'hardware':                

            //Date variables
            $day = $_POST['day'];
            $month = $_POST['month'];
            $year = $_POST['year'];

            //Function to make a valid date input
            $datepurchased = $year."-".$month."-".$day;

            //SQL Query to add tank info
            $qry = "update l_hardware set hmanufacturer='".$_POST['manufacturer']."',notes='".$_POST['notes']."', qty='".$_POST['qty']."', cost='".$_POST['cost']."',lname='".$_POST['name']."',hardware_type='".$_POST['hardtype']."', datepurchased='$datepurchased' where user_id='". $_SESSION['uid']."' and id='".$_GET['id']."'";
            
            break;                  
           }
           
        break;
      }
        
        //Execute Insert command
        if (!mysql_query($qry,$con))
            {
              die('Error: ' . mysql_error());
            }
            echo "Lighting updated!"; 
            //echo $qry;
               
    //Close SQL input
    mysql_close($con);

?>
